"""自定义的工具类,比如过滤器，g变量"""
import functools
import logging
from flask import session, g
from info.models import User


def do_index_class(index):
    if index == 1:
        return 'first'
    elif index == 2:
        return 'second'
    elif index == 3:
        return 'third'
    else:
        return


def outside(f):
    @functools.wraps(f)
    def inside(*args,**kwargs):
        use_id = session.get('id', None)
        use_data = None
        if use_id:
            try:
                # 用户登入的模型对象
                use_data = User.query.filter(User.id == use_id).first()
            except Exception as e:
                logging.error(e)
        g.use= use_data
        return f(*args,**kwargs)
    return inside
